package com.nahan.secondapplication.AppUpdate;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.nahan.secondapplication.R;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import constant.DownLoadBy;
import constant.UiType;
import listener.OnInitUiListener;
import model.UiConfig;
import model.UpdateConfig;
import update.UpdateAppUtils;

import static extension.CoreKtxKt.string;

/**
 * @describe: 描述：
 * @time: 2020-9-2 10:37:59
 */
public class AppUpdateActivity extends AppCompatActivity {
    private String apkUrl = "https://github.com/weaponbay/Test-Version/raw/master/app-debug.apk";
    private String updateTitle = "发现新版本V2.0.0";
    private String updateContent = "1、Kotlin重构版\n2、支持自定义UI\n3、增加md5校验\n4、更多功能等你探索";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_update);

        findViewById(R.id.start).setOnClickListener(v ->
                UpdateAppUtils
                        .getInstance()
                        .apkUrl(apkUrl)
                        .updateTitle(updateTitle)
                        .updateContent(updateContent)
                        .updateConfig(new UpdateConfig(true,true,false,true,false,"","", DownLoadBy.APP,false,true,0,false,true,"",0))
                        .uiConfig(new UiConfig(UiType.CUSTOM,R.layout.view_update_dialog_custom,null,null,null,null,null,null,null,null,null,string(R.string.update_now),null,null,null,null,string(R.string.update_cancel),string(R.string.toast_download_apk),string(R.string.downloading),string(R.string.download_fail)))
                        .setOnInitUiListener(new OnInitUiListener(){
                            @Override
                            public void onInitUpdateUi(@Nullable View view, @NotNull UpdateConfig updateConfig, @NotNull UiConfig uiConfig) {
                                TextView textView1=view.findViewById(R.id.tv_update_title);
                                TextView textView2=view.findViewById(R.id.tv_version_name);
                                textView1.setText("版本更新啦");
                                textView2.setText("V2.0.0");
                                // do more...
                            }

        })
                .update());
    }



}
